﻿using Guia.Core;

namespace GuiaTest
{
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using Guia.Elements;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using WpfTestApplication;

    /// <summary>
    ///This is a test class for UIElementTest and is intended
    ///to contain all UIElementTest Unit Tests
    ///</summary>
    [TestClass]
    public class MessageBoxTest : AbstractWindowTest
    {
        protected override Type TestWindowType()
        {
            return typeof(MessageBoxTestWindow);
        }

        protected override string TestWindowName()
        {
            return "MessageBoxTestWindow";
        }

        [TestMethod]
        public void TestMessageBoxText()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxOk");
            Label resultLabel = this.window.Get<Label>("lblResult");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            Assert.AreEqual("MessageBox Ok",messageBox.Text);
            messageBox.Ok();
        }

        [TestMethod]
        public void TestMessageBoxOk()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxOk");
            Label resultLabel = this.window.Get<Label>("lblResult");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            Assert.AreEqual(MessageBox.EMessageBoxType.OK, messageBox.MessageBoxType);
            messageBox.Ok();
            Assert.AreEqual("OK", resultLabel.TextValue);
        }

        [TestMethod]
        public void TestMessageBoxOkCancel()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxOkCancel");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            Assert.AreEqual(MessageBox.EMessageBoxType.OK_CANCEL, messageBox.MessageBoxType);
            messageBox.Ok();
        }

        [TestMethod]
        public void TestMessageBoxYesNo()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxYesNo");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            Assert.AreEqual(MessageBox.EMessageBoxType.YES_NO, messageBox.MessageBoxType);
            messageBox.Yes();
        }

        [TestMethod]
        public void TestMessageBoxYesNoCancel()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxYesNoCancel");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            Assert.AreEqual(MessageBox.EMessageBoxType.YES_NO_CANCEL, messageBox.MessageBoxType);
            messageBox.Yes();
        }

        [TestMethod]
        public void TestMessageBoxOkCancelOk()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxOkCancel");
            Label resultLabel = this.window.Get<Label>("lblResult");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            messageBox.Ok();
            Assert.AreEqual("OK", resultLabel.TextValue);
        }

        [TestMethod]
        public void TestMessageBoxOkCancelCancel()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxOkCancel");
            Label resultLabel = this.window.Get<Label>("lblResult");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            messageBox.Cancel();
            Assert.AreEqual("Cancel", resultLabel.TextValue);
        }

        [TestMethod]
        public void TestMessageBoxYesNoYes()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxYesNo");
            Label resultLabel = this.window.Get<Label>("lblResult");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            messageBox.Yes();
            Assert.AreEqual("Yes", resultLabel.TextValue);
        }

        [TestMethod]
        public void TestMessageBoxYesNoNo()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxYesNo");
            Label resultLabel = this.window.Get<Label>("lblResult");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            messageBox.No();
            Assert.AreEqual("No", resultLabel.TextValue);
        }

        [TestMethod]
        public void TestMessageBoxYesNoCancelYes()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxYesNoCancel");
            Label resultLabel = this.window.Get<Label>("lblResult");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            messageBox.Yes();
            Assert.AreEqual("Yes", resultLabel.TextValue);
        }

        [TestMethod]
        public void TestMessageBoxYesNoCancelNo()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxYesNoCancel");
            Label resultLabel = this.window.Get<Label>("lblResult");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            messageBox.No();
            Assert.AreEqual("No", resultLabel.TextValue);
        }

        [TestMethod]
        public void TestMessageBoxYesNoCancelCancel()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxYesNoCancel");
            Label resultLabel = this.window.Get<Label>("lblResult");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            messageBox.Cancel();
            Assert.AreEqual("Cancel", resultLabel.TextValue);
        }

        [TestMethod]
        public void TestMessageBoxYesInvalid()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxOk");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            try
            {
                messageBox.Yes();
                Assert.Fail();
            }
            catch (OperationNotSupportedException)
            {
                Assert.IsTrue(true);
            }
            finally
            {
                messageBox.Ok();
            }
        }

        [TestMethod]
        public void TestMessageBoxNoInvalid()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxOk");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            try
            {
                messageBox.No();
                Assert.Fail();
            }
            catch (OperationNotSupportedException)
            {
                Assert.IsTrue(true);
            }
            finally
            {
                messageBox.Ok();
            }
        }

        [TestMethod]
        public void TestMessageBoxCancelInvalid()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxOk");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            try
            {
                messageBox.Cancel();
                Assert.Fail();
            }
            catch (OperationNotSupportedException)
            {
                Assert.IsTrue(true);
            }
            finally
            {
                messageBox.Ok();
            }
        }

        [TestMethod]
        public void TestMessageBoxOkInvalid()
        {
            Button invokeButton = this.window.Get<Button>("btnShowMessageBoxYesNo");
            invokeButton.Invoke();
            MessageBox messageBox = this.window.GetMessageBox("Some Information");
            try
            {
                messageBox.Ok();
                Assert.Fail();
            }
            catch (OperationNotSupportedException)
            {
                Assert.IsTrue(true);
            }
            finally
            {
                messageBox.Yes();
            }
        }
    }
}
